const api = require('@api/store_api');
import { err, to, get, set } from '@utils/wxapi';
Page({
  data: {
    token: '',
    user: {},
    mch: {},
    rect: {},
    mop: [
      { title: '会员列表', img: '../../images/vip.png', url: '/dj/pages/vip/vip' },
      { title: '商品分类', img: '../../images/goodtype.png', url: '/dj/pages/type/type' },
      { title: '商品列表', img: '../../images/good.png', url: '/dj/pages/goods/goods' },
      { title: '消费账单', img: '../../images/bill.png', url: '/dj/pages/bill/bill' },
      { title: '餐桌列表', img: '../../images/board.png', url: '/dj/pages/board/board' },
      { title: '查看营收', img: '../../images/skdp.png', url: '/dj/pages/skdp/skdp' },
      { title: '充值活动', img: '../../images/pay.png', url: '/dj/pages/payhd/payhd' },
      { title: '会员积分变更', img: '../../images/points.png', url: '/dj/pages/points/points' },
      { title: '退款列表', img: '../../images/payreturn.png', url: '/dj/pages/payreturn/payreturn' },
    ],
    store: [
      { title: '个人中心', img: '../../images/myinfo.png', url: '/user/pages/myinfo/myinfo' },
      { title: '消费记录', img: '../../images/bill.png', url: '/user/pages/bill/bill' },
      { title: '积分详情', img: '../../images/points.png', url: '/user/pages/points/points' },
      { title: '退款列表', img: '../../images/payreturn.png', url: '/user/pages/payreturn/payreturn' },
      { title: '充值活动', img: '../../images/pay.png', url: '/user/pages/pay/pay' },
      { title: '分配角色', img: '../../images/mop.png', url: '/pages/store/store' },
      { title: '用户协议', img: '../../images/xieyi.png', url: '/user/pages/xieyi/xieyi' },
      { title: '隐私政策', img: '../../images/yinsi.png', url: '/user/pages/yinsi/yinsi' },
    ],
  },
  onLoad() {
    const rect = wx.getMenuButtonBoundingClientRect();
    this.setData({ rect });
    this.setData({ user: get('user') });
  },
  onShow() {
    this.getuser();
    this.setData({ token: get('token'), mch: get('mch') });
  },
  async getuser() {
    api
      .getuser()
      .then(({ respCode, source }) => {
        if (respCode === 200) {
          const user = JSON.parse(source);
          this.setData({ user });
          set('user', user);
        }
      })
      .catch(error => {
        err(error);
      });
  },
  jump(e) {
    const { url } = e.currentTarget.dataset;
    to(url);
  },
  tovip() {
    to('/user/pages/myinfo/myinfo');
  },
  shop() {
    wx.showModal({
      title: '提示',
      content: '您确定退出商家吗？',
      complete: res => {
        if (res.confirm) {
          wx.removeStorage({ key: 'token' });
          this.setData({ token: '' });
        }
      },
    });
  },
});
